import {RouteItem} from "../../Pages/type";
import React from "react";

export function selectRoutes(k:string, rs:RouteItem[]| RouteItem ): RouteItem|null{
  if(!Array.isArray(rs)){
    let item = selectRoute(rs,k);
    if(item){
      return item;
    }
    return null;
  }

  for(let i in rs){
    let item = rs[i];
    let mItem = selectRoute(item, k);
    if(mItem){
      return mItem;
    }
  }
  return null;
}
function selectRoute (rs : RouteItem,  k:string):  RouteItem|null{
  if(rs.hide){
    return null;
  }
  if(rs.key && rs.name && rs.component){
    if(!Array.isArray(rs.children)){
      if( rs.key === k ){
        return rs;
      }
      return null;
    }

    let menus = selectRoutes(k,rs.children);
    if(menus){
      return menus;
    }
    return null;
  }
  return null;
}
const NotFound=()=><div>不存在这个key</div>;
export const NotFountRoute:RouteItem = {name:"异常分支",key:"undefined",showMap:false,component:NotFound};
